package com.sqm.conntroller;

import com.sqm.entity.Shujia;
import com.sqm.entity.User;
import com.sqm.model.Novel;
import com.sqm.service.NovelService;
import com.sqm.service.ShujaService;
import com.sqm.service.UserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 功能:
 * 作者: 沙琪马
 * 日期: 2024/6/7 12:40
 */

@RestController
@RequestMapping("novels")
@Slf4j
public class NovelController {
    @Resource
    private NovelService novelService;

    @Resource
    private ShujaService shujaService;


    @GetMapping
    public List<Novel> getNovels() {
        return novelService.getNovels();
    }

    @GetMapping("/first")
    public Page<Novel>  getNovelsByType(@RequestParam("type")String type,
                                       @RequestParam("page")int page,
                                       @RequestParam("size")int size) {
        log.info("查询小说类型为:{}", type);
        return novelService.getNovelsByType(type, page, size);
    }

    @GetMapping("/sou")
    public Page<Novel> getNovelsByName(@RequestParam("name")String name,
                                       @RequestParam("page")int page,
                                       @RequestParam("size")int size) {
        log.info("查询小说名称为:{}", name);
        return novelService.getNovelsByName(name, page, size);
    }

    @GetMapping("/shujia")
    public List<Novel> getNovelsByShujia(@RequestParam("id")String id) {
        log.info("查询我的书架:{}", id);
        return shujaService.getByName(id);
    }
    @PostMapping("/shujia")
    public void addShujia(@RequestBody Shujia shujia) {
        log.info("添加书架:{}", shujia.getShuId());
        shujaService.add(shujia);
    }

    @GetMapping("/chars")
    public List<Map<String, Object>> getChars(){
        return shujaService.getChars();
    }

    @GetMapping("/shujia/exist")
    public Boolean getShujiaExists(@RequestParam String id){
        return shujaService.getShujiaExists(id);
    }

    @DeleteMapping("/shujia")
    public void deleteShujia(@RequestParam String id){
        shujaService.deleteShujia(id);
    }
}
